package com.ht.demo.service.convert.monitor;

import com.ht.demo.common.pojo.bo.monitor.SysLoggerBO;
import com.ht.demo.dao.domain.monitor.SysLoggerDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类SysLoggerBeanUtil.java的实现描述：系统操作日志工具类
 * 
 * @Author hdengxian
 * @Date 2023年05月30日
 */
public class SysLoggerBeanUtil {

    private SysLoggerBeanUtil(){
    }

    public static SysLoggerDO sysLoggerBOToDO(SysLoggerBO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysLoggerDO targetObj = new SysLoggerDO();
        /**id**/
        targetObj.setId(srcObj.getSysLoggerId());
        /**操作模块**/
        targetObj.setTitle(srcObj.getTitle());
        /**操作类型**/
        targetObj.setOperateType(srcObj.getOperateType());
        /**请求类名**/
        targetObj.setClazzName(srcObj.getClazzName());
        /**请求方法**/
        targetObj.setMethod(srcObj.getMethod());
        /**请求方式**/
        targetObj.setRequestType(srcObj.getRequestType());
        /**主机地址**/
        targetObj.setOperIp(srcObj.getOperIp());
        /**操作人员**/
        targetObj.setOperName(srcObj.getOperName());
        /**操作时间**/
        targetObj.setOperTime(srcObj.getOperTime());
        /**请求URL**/
        targetObj.setOperUrl(srcObj.getOperUrl());
        /**消耗时间**/
        targetObj.setCostTime(srcObj.getCostTime());
        /**请求参数**/
        targetObj.setOperParam(srcObj.getOperParam());
        /**返回参数**/
        targetObj.setJsonResult(srcObj.getJsonResult());
        /**错误消息**/
        targetObj.setErrorMsg(srcObj.getErrorMsg());
        targetObj.setLocation(srcObj.getLocation());
        targetObj.setStatus(srcObj.getStatus());

        return targetObj;
    }

    public static SysLoggerBO sysLoggerDOToBO(SysLoggerDO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysLoggerBO targetObj = new SysLoggerBO();
        /**id**/
        targetObj.setSysLoggerId(srcObj.getId());
        /**操作模块**/
        targetObj.setTitle(srcObj.getTitle());
        /**操作类型**/
        targetObj.setOperateType(srcObj.getOperateType());
        /**请求类名**/
        targetObj.setClazzName(srcObj.getClazzName());
        /**请求方法**/
        targetObj.setMethod(srcObj.getMethod());
        /**请求方式**/
        targetObj.setRequestType(srcObj.getRequestType());
        /**主机地址**/
        targetObj.setOperIp(srcObj.getOperIp());
        /**操作人员**/
        targetObj.setOperName(srcObj.getOperName());
        /**操作时间**/
        targetObj.setOperTime(srcObj.getOperTime());
        /**请求URL**/
        targetObj.setOperUrl(srcObj.getOperUrl());
        /**消耗时间**/
        targetObj.setCostTime(srcObj.getCostTime());
        /**请求参数**/
        targetObj.setOperParam(srcObj.getOperParam());
        /**返回参数**/
        targetObj.setJsonResult(srcObj.getJsonResult());
        /**错误消息**/
        targetObj.setErrorMsg(srcObj.getErrorMsg());
        targetObj.setLocation(srcObj.getLocation());
        targetObj.setStatus(srcObj.getStatus());

        return targetObj;
    }

    public static List<SysLoggerBO> doList2BOList(List<SysLoggerDO> doList) {
        List<SysLoggerBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) return boList;

        doList.stream().forEach(d -> boList.add(SysLoggerBeanUtil.sysLoggerDOToBO(d)));
        return boList;
    }

    public static List<SysLoggerDO> boList2DOList(List<SysLoggerBO> boList) {
        List<SysLoggerDO> doList = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) return doList;

        boList.stream().forEach(b -> doList.add(SysLoggerBeanUtil.sysLoggerBOToDO(b)));
        return doList;
    }
}